package com.cookie.framework.view;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.cookie.framework.R;
import com.cookie.framework.manager.DialogManager;
import com.cookie.framework.utils.AnimUtils;

/**
 * 项目名:    MeetProject
 * 包名:      com.cookie.framework.view
 * 文件名:    LoadingView
 * 创建者:    cookie
 * 创建时间:   2020/1/2 0:48
 * 描述:      加载提示框
 */

public class LoadingView {

    private DialogView dialogView;
    private ImageView ivLoading;
    private TextView tvLoadingText;
    private ObjectAnimator objectAnimator;

    public LoadingView(Context context) {
        dialogView = DialogManager.getInstance().initView(context, R.layout.dialog_loading);
        ivLoading = dialogView.findViewById(R.id.iv_loading);
        tvLoadingText = dialogView.findViewById(R.id.tv_loading_text);
        objectAnimator = AnimUtils.rotation(ivLoading);
    }

    //设置加载的提示文本
    public void setLoadingText(String text) {
        if (!TextUtils.isEmpty(text)) {
            tvLoadingText.setText(text);
        }
    }

    public void show(){
        objectAnimator.start();
        DialogManager.getInstance().show(dialogView);
    }

    public void show(String text){
        objectAnimator.start();
        setLoadingText(text);
        DialogManager.getInstance().show(dialogView);
    }

    public void hide(){
        objectAnimator.pause();
        DialogManager.getInstance().hide(dialogView);
    }

    public void setCancelable(boolean flag){
        dialogView.setCancelable(flag);
    }
}
